#ifndef VSL_H
#define VSL_H

#include <string>
#include <list>

#include <iostream>
#include <sstream>

#include <vector>

#include "ast.h"

enum TokenType {
    TOK_NUMBER,
    TOK_TEXT,
    TOK_VARIABLE,
    TOK_ASSIGN_SYMBOL,      /* := */
    TOK_FUNC,               /* Keyword: FUNC */
    TOK_PRINT,              /* Keyword: PRINT */
    TOK_RETURN,             /* Keyword: RETURN */
    TOK_CONTINUE,           /* Keyword: CONTINUE */
    TOK_IF,                 /* Keyword: IF */
    TOK_THEN,               /* Keyword: THEN */
    TOK_ELSE,               /* Keyword: ELSE */
    TOK_FI,                 /* Keyword: FI */
    TOK_WHILE,              /* Keyword: WHILE */
    TOK_DO,                 /* Keyword: DO */
    TOK_DONE,               /* Keyword: DONE */
    TOK_VAR,                /* Keyword: VAR */
    TOK_NEWLINE,            /* Newline */
    TOK_COMMENT,            /* Comment: // */
    TOK_BINARY,             /* Operator: '+', '-', '*', '/' */
    TOK_UNKNOWN,            /* Unknown Token Type */
    TOK_LPAREN,             /* Left Paren: '(' */
    TOK_RPAREN,             /* Right Paren: ')' */
    TOK_LCURLY,             /* Left Curly: '{' */
    TOK_RCURLY,             /* Right Curly: '}' */
    TOK_COMMA,              /* Comma: ',' */
    TOK_STRING,             /* String: "string" */
    TOK_EOF                 /* End of File */
};

struct Token {
    TokenType type;
    std::string text;
    //int integer;
};

const static std::string tokstr[] = {"NUMBER", "TEXT", "VARIABLE", "ASSIGN_SYMBOL", "FUNC", "PRINT", "RETURN",
    "CONTINUE", "IF", "THEN", "ELSE", "FI", "WHILE", "DO", "DONE", "VAR", "NEWLINE", "COMMENT", "BINARY",
    "UNKNOWN", "LPAREN", "RPAREN", "LCURLY", "RCURLY", "COMMA", "STRING", "EOF"};

class VSL
{
public:
    std::list<Token> tokens;
    //std::string text;
    std::stringstream codebuf;
private:
    Token tok;
public:
    VSL(std::streambuf *buf);
    void lexer();
    void dumptoks();
    void printtok();
    void parser();

    BaseAST *programParser();
    FuncAST *funcParser();
    FuncDeclAST *funcDeclParser();
    BaseAST *blockStmtParser();
    BaseAST *declParser();
    BaseAST *stmtParser();
    BaseAST *assignStmtParser();
    BaseAST *returnStmtParser();
    BaseAST *printStmtParser();
    BaseAST *nullStmtParser();
    BaseAST *ifStmtParser();
    BaseAST *whileStmtParser();

    void ASTVistor();
private:
    TokenType gettok();
    TokenType getk();
    TokenType getTokType();
    std::string getTokStr();
};



#endif // VSL_H
